import { Schema, ObjectId, db } from './mongo'

// 用户
const UserSchema = new Schema({
  username: {
    type: String,
    required: true,
    index: true,
    unique: true,
    check: [2, 22],
    remark: '用户名',
  },
  password: {
    type: String,
    required: true,
    default: '123456',
    index: true,
    check: [6, 32],
    remark: '密码',
  },
  icon: {
    type: String,
    remark: '头像',
  },
  phone: {
    type: String,
    check: 'phone',
    remark: '电话号码',
  },
  sex: {
    type: Number,
    required: true,
    check: [0, 1, 2],
    default: 0,
    remark: '性别',
  },
  school: {
    type: ObjectId,
    ref: 'school',
    remark: '所在学校',
  },
  year: {
    type: String,
    remark: '入学年份',
  },
  major: {
    type: ObjectId,
    ref: 'major',
    remark: '专业',
  },
  edu: {
    type: Number,
    check: [0, 1, 2, 3, 4, 5],
    default: 0,
    remark: '学历',
  },
  qq: {
    type: String,
    check: [3, 20],
    remark: 'QQ号码',
  },
  wechat: {
    type: String,
    check: [3, 20],
    remark: '微信号',
  },
  email: {
    type: String,
    check: 'email',
    remark: '邮箱',
  },
  address: {
    type: String,
    check: [2, 50],
    remark: '通信地址',
  },
  doc: {
    type: [ObjectId],
    ref: 'document',
    remark: '相关资料',
  },
  group: {
    type: [ObjectId],
    ref: 'group',
    remark: '所在组别',
  },
  state: {
    type: Number,
    required: true,
    default: 0,
    remark: '状态',
  },
  isAdmin: {
    type: Boolean,
    required: true,
    default: false,
    remark: '是否能登录系统',
  },
  lastLogin: {
    type: String,
    remark: '上次登录IP',
  },
}, {
  collection: 'user',
  timestamps: true,
})

export default db.model('user', UserSchema)
